package org.javaboy.security_role_permission.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.javaboy.security_role_permission.model.Permission;
import org.javaboy.security_role_permission.model.Role;
import org.javaboy.security_role_permission.model.User;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user where username=#{username};")
    User getUserByName(String username);

    @Select("SELECT r.* FROM ROLE r,user_role ur WHERE ur.`rid`=r.`id` AND ur.`uid`=#{id}")
    List<Role> getRolesByUserId(Integer id);

    @Select("SELECT p.* FROM permissions p,role_permissions rp,user_role ur WHERE ur.`rid`=rp.`rid` AND rp.`pid`=p.`pid` AND ur.`uid`=#{id}")
    List<Permission> getPermissionsByUserId(Integer id);
}
